<template>
	<view>
		<view class="item themeBac cwhite f-c">
			<image src="../../static/my/icon_xgsjh.png" mode="widthFix"></image>
			<input type="tel" @input="inputMo" placeholder="请输入新手机号" />
		</view>

		<view class="item themeBac cwhite f-c">
			<image src="../../static/my/icon_yzm.png" mode="widthFix"></image>
			<input type="number" @input="inputCode" placeholder="请输入验证码" />
			<view class="getCode" @click="getCode">{{tips}}</view>

			<u-verification-code :seconds="seconds" ref="uCode" @change="codeChange">
			</u-verification-code>
		</view>

		<view class="btn">
			<button @click="toNext" class="themeBac cwhite">确定</button>
		</view>
		<text>11111{{tips}}</text>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tips: '',
				seconds: 60,
				mobile: "",
				code: "",
			}
		},
		methods: {
			inputMo(v) {
				this.mobile = v.detail.value
			},
			inputCode(v) {
				this.code = v.detail.value
			},
			codeChange(text) {
				console.log(text);
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						this.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
				} else {
					this.$u.toast('倒计时结束后再发送');
				}
			},
			toNext() {
				if (!this.$u.test.mobile(this.mobile)) {
					this.$u.toast('请输入正确的手机号！')
					return;
				}
				this.$back(2)
			}
		}
	}
</script>

<style>
	.item {
		margin: 30rpx 80rpx;
		border-radius: 10rpx;
		padding: 17rpx;
	}

	.item image {
		width: 30rpx;
		margin-right: 20rpx;
	}

	.item input {
		border-left: 4rpx solid #FFFFFF;
		padding-left: 20rpx;
	}

	.input-placeholder {
		font-size: 28rpx;
		color: #FFFFFF;
	}

	.getCode {
		white-space: nowrap;
		border-left: 4rpx solid #FFFFFF;
		padding-left: 10rpx;
		font-size: 28rpx;
	}

	.btn {
		margin: 100rpx 80rpx;
	}
</style>
